package com.bjsxt.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;

/**
 * 日期工具类
 * @author wangshSxt
 *
 */
@Component("dateFormatUtil")
public class DateFormatUtil
{
	/**
	 * 日期格式化
	 * 将日期转换为字符串
	 * @return
	 */
	public String format(Date date,String pattern)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	/**
	 * 将字符串转化为日期
	 * @param timeStr
	 * @param pattern
	 * @return
	 */
	public Date format(String timeStr,String pattern)
	{	
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		try
		{
			return sdf.parse(timeStr);
		} catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null ;
	}
}
